<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class ProductsGroup extends Model
{
    public function getProductItemAttr($value)
    {
        if(!empty($value)){
            return json_decode($value);
        }else{
            return $value;
        }
    }

    /**
     * 产品分类
     * @return \think\model\relation\HasOne
     */
    public function cate()
    {
        return $this->hasOne(ProductsType::class,'id','products_type_id')->field('id,name');
    }

    /**
     * 品牌
     * @return \think\model\relation\HasOne
     */
    public function pp()
    {
        return $this->hasOne(Brand::class,'id','brand_id')->field('id,name');
    }

    /**
     * 单位
     * @return \think\model\relation\HasOne
     */
    public function dw()
    {
        return $this->hasOne(Unit::class,'id','unit_id')->field('id,name');
    }
}
